﻿using AutoMapper;
using MediatR;
using RBAC.Api.Demain.Entities;
using RBAC.Api.Erroc;
using RBAC.Api.Infaction;
using RBAC.Api.Writh.Command.Permissions;

namespace RBAC.Api.Writh.CommandHandler.Permissions
{
    public class UpdatePermissionCommandHandler : IRequestHandler<UpdatePermissionCommand, APIResult<object>>
    {
        private readonly IBaseRepositry<Permission> dal;
        private readonly IMapper mapper;
        private readonly ILogger<UpdatePermissionCommandHandler> logger1;

        public UpdatePermissionCommandHandler(IBaseRepositry<Permission> baseRepositry, IMapper mapper,ILogger<UpdatePermissionCommandHandler> logger1)
        {
            dal = baseRepositry;
            this.mapper = mapper;
            this.logger1 = logger1;
        }
        public async Task<APIResult<object>> Handle(UpdatePermissionCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code = ResultCode.Success;
            result.Message = "修改权限成功";

            var model = mapper.Map<Permission>(request);
            logger1.LogInformation("修改权限开始");
            await dal.Update(model);
            return await Task.FromResult(result);
        }
    }
}
